#ifndef GWSCENE_H
#define GWSCENE_H

#include <QGraphicsScene>

#include "gwrectangle.h"
#include "GwGraphics_global.h"
#include "gwdetector.h"
#include "gwtext.h"
#include "GraphicsType.h"



class GWGRAPHICS_EXPORT GwScene : public QGraphicsScene
{
    Q_OBJECT
public:
    GwScene(QObject *parent = 0);
    ~GwScene();
//    void addGWRect(GwRectangle *rect);
//    void removeGWRect(GwRectangle *rect);
    void setBackgroundPic(QString filename);
    void addItem(QGraphicsItem *item);
    void removeItem(QGraphicsItem *item);
    QList<GwDetector *> getDetectorList();
    QList<GwRectangle *> getRoomList();
    QString backgroundFile;
    QString getSceneProjectFile();
    QList<GwScene *> childs;
    void setParentScene(GwScene *parent);
    GwScene* getParentScene();
    StateInfo getRoomStateInfo();

private:
    QList<GwDetector *>lst_gw_detector;
    QList<GwRectangle *>lst_gw_rects;
    QList<GwText *>lst_gw_txts;
    QGraphicsPixmapItem *background=NULL;
    QByteArray packGwDetector();
    QByteArray packGWRect();
    QByteArray packGWText();
    QByteArray packGWScene();
    void unpackGWScene(QByteArray data, bool isconfig);
    void unpackGWRect(QByteArray data,bool isconfig);
    void unpackGWDetector(QByteArray data, bool isconfig);
    void unpackGWText(QByteArray data, bool isconfig);
    QString ProFile;
    GwScene *parentScene=nullptr;
    StateInfo dev_cnt={0,0,0,0};
    StateInfo total_cnt={0,0,0,0};

public slots:
    void save();
    void load(bool isconfig);
    void load(QString filename,bool isconfig);
    void stateChanged(GraphicsState info);

signals:
    void warnCntChange(StateInfo info);

    // QGraphicsScene interface
protected:
    void keyPressEvent(QKeyEvent *event);

};

#endif // GWSCENE_H
